package com.kgc.ssm.service.impl;

import com.kgc.ssm.entity.*;
import com.kgc.ssm.entity.dto.Result;
import com.kgc.ssm.mapper.*;
import com.kgc.ssm.service.PurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Map;

@Service
public class PurchaseServiceImpl implements PurchaseService {

    @Resource
    private StockMapper stockMapper;
    @Resource
    private EnquireMapper enquireMapper;
    @Resource
    private QuoteMapper quoteMapper;
    @Resource
    private OrdersMapper ordersMapper;
    @Resource
    private ContractMapper contractMapper;
    @Resource
    private ContractApplyMapper contractApplyMapper;
    @Resource
    private ContractDetailMapper contractDetailMapper;

    //单表查询所有数据
    @Override
    public List<Stock> findAll() {
        return stockMapper.selectByExample(null);
    }

    //多表查询所有数据 为了获取到物资名称这一个参数
    @Override
    public List<Stock> findAll2() {
        return stockMapper.findAll2();
    }

    @Override
    public Map<String, Object> findById(Integer id){
        return stockMapper.findById1(id);
    }

    @Override
    public int updateAll(Map<String, Object> param) {
        return stockMapper.updateAll(param);
    }

    @Override
    public List<Map<String, Object>> getAllList() {
        return enquireMapper.getAllList();
    }

    @Override
    public int DeleteById(Integer id) {
        int i = enquireMapper.DeleteById(id);
        int j = enquireMapper.DeleteQuoteById(id);
        System.out.println("I："+i);
        System.out.println("J："+j);
        return i;
    }

    @Override
    public List<Map<String, Object>> selectAllQE(Integer id) {
        return enquireMapper.selectAllQE(id);
    }

    @Override
    public List<Map<String, Object>> selectQuoted(Integer id) {
        return enquireMapper.selectQuoted(id);
    }

    @Override
    public List<Map<String,Object>> findAllQuote(Integer id) {
        return enquireMapper.findAllQuote(id);
    }

    @Override
    public List<Map<String, Object>> selectAllQD(Integer id) {
        return quoteMapper.selectAllQD(id);
    }

    @Override
    public List<Map<String, Object>> findAllQE(Integer id) {
        return enquireMapper.findAllQE(id);
    }

    @Override
    public List<Map<String, Object>> selectByIdOP(Integer id) {
        return ordersMapper.selectByIdOP(id);
    }

    @Override
    public List<Enquire> selectByIdEnquire(Integer id) {
        EnquireExample enquireDetail = new EnquireExample();
        enquireDetail.createCriteria().andIdEqualTo((long)id);
        return enquireMapper.selectByExample(enquireDetail);
    }

    @Override
    public int updateEnquire(Map<String, Object> params) {
        System.out.println("实现类的:"+params);
        // 执行更新操作
        return enquireMapper.updateEnquire(params);
    }

    @Override
    public int updateOrder(Map<String, Object> params) {
        return ordersMapper.updateByOrders(params);
    }

    @Override
    public List<Contract> selectAllContract() {
        return contractMapper.selectByExample(null);
    }

    @Override
    public List<ContractApply> selectAllContractApply() {
        return contractApplyMapper.selectByExample(null);
    }

    @Override
    public List<Map<String, Object>> selectAllAppEnquire() {
        return contractApplyMapper.selectAlAppEnquire();
    }

    @Override
    public Enquire selectByName(String enquireNum) {
        return enquireMapper.selectByEnquire_Num(enquireNum);
    }

    @Override
    public List<ContractDetail> selectByContIdList(Integer id) {
        ContractDetailExample example = new ContractDetailExample();
        example.createCriteria().andContIdEqualTo(id.longValue());
        return contractDetailMapper.selectByExample(example);
    }


}
